package com.groupseven.happycampus.controller;

import com.groupseven.happycampus.common.pojo.BicycleSupplier;
import com.groupseven.happycampus.common.result.R;
import com.groupseven.happycampus.common.vo.BicycleSupplierBrandPieVo;
import com.groupseven.happycampus.common.vo.BicycleSupplierNameBarVo;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.service.BicycleSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.text.normalizer.UBiDiProps;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/bicycleSupplier")
public class BicycleSupplierController {

    @Autowired
    private BicycleSupplierService bicycleSupplierService;

    @RequestMapping("/supplierList")
    public LayuiPageVo<BicycleSupplier> bicycleSupplierList(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        return bicycleSupplierService.bicycleSupplierList(params);
    }

    @RequestMapping("/bicycleSupplierAdd")
    public R bicycleSupplierAdd(BicycleSupplier bicycleSupplier) {
        int i = bicycleSupplierService.bicycleSupplierAdd(bicycleSupplier);
        if (i == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @RequestMapping("/bicycleSupplierUpdate")
    public R bicycleSupplierUpdate(BicycleSupplier bicycleSupplier) {
        int i = bicycleSupplierService.bicycleSupplierUpdate(bicycleSupplier);
        if (i == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @RequestMapping("/bicycleSupplierDelete")
    public R bicycleSupplierDelete(@RequestParam("bicycleSupplierId") Integer id) {
        int i = bicycleSupplierService.bicycleSupplierDelete(id);
        if (i == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @RequestMapping("/deleteSupplierByIds")
    public R deleteSupplierByIds(@RequestParam String ids) {
        System.out.println("ids========="+ids);
        int i = bicycleSupplierService.deleteSupplierByIds(ids);
        if (i > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }


    @RequestMapping("/echartNameBar")
    public R echartNameBar() {
        List<BicycleSupplierNameBarVo> list = bicycleSupplierService.echartNameBar();
        System.out.println(list);
        return R.ok().data("supplierNameBar", list);
    }

    @RequestMapping("/echartsBrandPie")
    public R echartsBrandPie() {
        List<BicycleSupplierBrandPieVo> list = bicycleSupplierService.echartsBrandPie();
        System.out.println(list);
        return R.ok().data("supplierBrandPie", list);
    }


}
